#!/bin/sh

handle=$1;
remoteIp="94.191.44.66";
remoteDir="/root/kuan-docker/nginx/webroot/web/m";

# 远程文件夹
clearRemote(){
   echo "[exec]删除远程文件:$remoteIp $remoteDir"
   ssh root@$remoteIp "mkdir $remoteDir -p ; rm -rf $remoteDir/*"
}

# 上传文件
uploadDist(){
   echo "[exec]正在上传文件:$remoteIp $remoteDir"
   scp -r ./dist/* root@$remoteIp:$remoteDir
}

echo "[exec]开始自动部署..."
   
if [ $handle == "build" ]
then
  npm run build
fi

clearRemote
uploadDist
echo "成功部署--"
